<!--
 * @Descripttion: 车费提现申请
 * @Author: xiao li
 * @Date: 2021-03-15 14:28:04
 * @LastEditors: xiao li
 * @LastEditTime: 2022-07-21 15:06:04
-->
<template>
  <div class="lb-finance-record">
    <top-nav></top-nav>
    <div class="page-main">
      <el-row class="page-search-form">
        <el-form
          @submit.native.prevent
          :inline="true"
          :model="searchForm"
          ref="searchForm"
        >
          <el-form-item label="状态" prop="status">
            <el-select
              @change="getTableDataList(1)"
              v-model="searchForm.status"
              placeholder="请选择"
            >
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="提现号" prop="code">
            <el-input
              v-model="searchForm.code"
              placeholder="请输入提现号"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <lb-button
              size="medium"
              type="primary"
              icon="el-icon-search"
              style="margin-right: 5px"
              @click="getTableDataList(1)"
              >{{ $t('action.search') }}</lb-button
            >
            <lb-button
              size="medium"
              icon="el-icon-refresh-left"
              style="margin-right: 5px"
              @click="resetForm('searchForm')"
              >{{ $t('action.reset') }}</lb-button
            >
          </el-form-item>
        </el-form>
      </el-row>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
        style="width: 100%"
      >
        <el-table-column prop="id" label="ID" fixed></el-table-column>
        <el-table-column prop="coach_name" label="姓名"></el-table-column>
        <el-table-column
          prop="code"
          label="提现号"
          width="150"
        ></el-table-column>
        <el-table-column
          prop="text"
          label="提现账号"
          width="200"
        ></el-table-column>
        <el-table-column prop="apply_price" label="申请金额">
          <template slot-scope="scope">
            <span>¥{{ scope.row.apply_price }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="apply_price" label="到账金额">
          <template slot-scope="scope">
            <span>¥{{ scope.row.apply_price }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="total_price" label="提现类型">
          <template slot-scope="scope">
            <span>{{ scope.row.type | typeText() }}</span>
          </template></el-table-column
        >
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <span>{{ statusType[scope.row.status] }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="申请时间" min-width="120">
          <template slot-scope="scope">
            <p>{{ scope.row.create_time | handleTime(1) }}</p>
            <p>{{ scope.row.create_time | handleTime(2) }}</p>
          </template>
        </el-table-column>
        <el-table-column label="处理时间" min-width="120">
          <template slot-scope="scope">
            <div v-if="scope.row.status !== 1">
              <p>{{ scope.row.sh_time | handleTime(1) }}</p>
              <p>{{ scope.row.sh_time | handleTime(2) }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="220">
          <template slot-scope="scope">
            <div class="table-operate">
              <block v-if="scope.row.status === 1">
                <lb-button
                  size="mini"
                  plain
                  type="primary"
                  @click="confirmWxCash(scope.row.id)"
                  >在线转账</lb-button
                >
                <lb-button
                  size="mini"
                  plain
                  type="success"
                  @click="confirmAccount(scope.row.id)"
                  >线下转账</lb-button
                >
                <lb-button
                  size="mini"
                  plain
                  type="danger"
                  @click="refuseAccount(scope.row.id)"
                  >拒绝提现</lb-button
                >
              </block>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <lb-page
        :batch="false"
        :page="searchForm.page"
        :pageSize="searchForm.limit"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      >
      </lb-page>
    </div>
  </div>
</template>

<script>
import moment from 'moment';
export default {
  data () {
    return {
      statusOptions: [
        {
          label: '全部',
          value: 0,
        },
        {
          label: '未到账',
          value: 1,
        },
        {
          label: '已到账',
          value: 2,
        },
        {
          label: '已拒绝',
          value: 3,
        },
      ],
      statusType: {
        1: '未到账',
        2: '已到账',
        3: '已拒绝',
      },
      searchForm: {
        page: 1,
        limit: 10,
        // type: 2,
        status: 0,
        code: '',
      },
      loading: false,
      total: 0,
      tableData: [],
    };
  },
  created () {
    this.getTableDataList();
  },
  methods: {
    resetForm (form) {
      this.$refs[form].resetFields();
      this.getTableDataList(1);
    },
    handleSizeChange (val) {
      this.searchForm.limit = val;
      this.handleCurrentChange(1);
    },
    handleCurrentChange (val) {
      this.searchForm.page = val;
      this.getTableDataList();
    },
    async getTableDataList (flag) {
      if (flag) this.searchForm.page = 1;
      this.loading = true;
      let { searchForm } = this;
      let { code, data } = await this.$api.finance.walletList(searchForm);
      this.loading = false;
      if (code !== 200) return;
      this.tableData = data.data;
      this.total = data.total;
    },
    /**
     * @method 在线转账
     */
    confirmWxCash (id) {
      this.$confirm(
        this.$t('tips.confirmOperate'),
        this.$t('tips.reminder'),
        {
          confirmButtonText: this.$t('action.comfirm'),
          cancelButtonText: this.$t('action.cancel'),
          type: 'warning',
        }
      ).then(() => {
        this.$api.finance
          .walletPass({ id, status: 2, online: 1 })
          .then((res) => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successOper'));
              this.getTableDataList();
            }
          });
      });
    },
    /**
     * @method 线下转账
     */
    confirmAccount (id) {
      this.$confirm(
        this.$t('tips.confirmOperate'),
        this.$t('tips.reminder'),
        {
          confirmButtonText: this.$t('action.comfirm'),
          cancelButtonText: this.$t('action.cancel'),
          type: 'warning',
        }
      ).then(() => {
        this.$api.finance
          .walletPass({ id, status: 2, online: 0 })
          .then((res) => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successOper'));
              this.getTableDataList();
            }
          });
      });
    },
    /**
     * @method 拒绝提现
     */
    refuseAccount (id) {
      this.$confirm(`你确认要拒绝提现吗？`, this.$t('tips.reminder'), {
        confirmButtonText: this.$t('action.comfirm'),
        cancelButtonText: this.$t('action.cancel'),
        type: 'warning',
      }).then(() => {
        this.$api.finance
          .walletNoPass({ id, status: 3 })
          .then((res) => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successOper'));
              this.getTableDataList();
            }
          });
      });
    },
  },
  filters: {
    handleTime (val, type) {
      let time =
        type === 1
          ? moment(val * 1000).format('YYYY-MM-DD')
          : type === 2
            ? moment(val * 1000).format('HH:mm:ss')
            : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss');
      return time;
    },
    typeText (val) {
      let texts = ['车费', '服务费', '代理商', '用户分销'];
      return texts[val - 1];
    },
  },
};
</script>

<style lang="scss" scoped>
.lb-finance-record {
  width: 100%;
}
</style>
